#ifndef LSFEATUREOBJECT_H
#define LSFEATUREOBJECT_H
#include <vector>
#include <objectPoint.h>
#include<define.h>

#include "iostream"
using namespace std;

class LSfeatureObject
{
public:
    LSfeatureObject();
    ~LSfeatureObject()
    {

    }
    LSfeatureObject(vector<objectPoint> p,int sIdx,int eIdx,int idd);
   const LSfeatureObject & operator +=( LSfeatureObject B);
    eConvexHull getBoundingBox();
public :
        void reset();
        int length();
        LSfeatureObject *CopyTo();
        int  getPointCount();
        int getMiddleIndex();
        objectPoint getMiddlePoint();
        objectPoint   getStartPoint();
        objectPoint  getEndPoint();
        double getLength();
        float getDigonalBoundingBox();
        objectPoint getMaxPoint();
        double getWidth();
public:
    vector<objectPoint> Scan;
    int _startIndex;
    int _endIndex;
    int id;
    double confidenceFactor;
    double diagonal;
private:
    float MinValue(float v1, float v2)
    {
        return v1>v2 ? v2:v1;
    }

    float MaxValue(float v1, float v2)
    {
        return v1> v2 ? v1 : v2;
    }
    double distancePointLine (objectPoint my_point, objectPoint Lp1, objectPoint Lp2)
    {
            double a = my_point.getX();
            double b = my_point.getY();
            double x1 = Lp1.getX();
            double y1 = Lp1.getY();
            double x2 = Lp2.getX();
            double y2 = Lp2.getY();

            //Calculate parameter t in the distance forumla.
            double t = ( (a-x1) * (x2 - x1) + ( b - y1 ) * ( y2 - y1 ) ) / ( pow( x2 - x1 , 2 ) + pow( y2 - y1 , 2) );

            //Calculate distance depending on value of t.
            if (t <= 0)        // t <= 0: closest to start point
                    return sqrt( pow(a-x1,2) + pow(b-y1,2) );
            else if (t < 1)    // 0 < t < 1: closest to line segment
                    return sqrt( pow(a - x1 - t * x2 + t * x1 , 2) + pow( b - y1 - t * y2 + t * y1 , 2 ) );
            else               // t >= 1: closest to end point
                    return sqrt( pow(a - x2 , 2 ) + pow( b - y2 , 2 ) );
    }
};
#endif // LASERSEGMENT_H


